<template>
  <uni-nav-bar title="加注站" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package">
    <view style="font-size: 36rpx;">{{TeamInfo.station.name}}</view>
    <view style="margin: 10rpx 0px;">补液单价：{{TeamInfo.station.price}}元/公斤</view>
    <view>{{TeamInfo.station.address}}</view>
  </view>
  <view class="package space-between">
    <view class="direction-start">
      <view>账户余额（元）</view>
      <view><text>￥</text><text style="font-size: 60rpx;">{{TeamInfo.station.money}}</text></view>
    </view>
    <view class="direction-start">
      <view>总溶液（公斤）</view>
      <view><text style="font-size: 60rpx;">{{TeamInfo.station.amount}}</text></view>
    </view>
  </view>
  <view class="package space-between ability" style="background: transparent;padding: 0px;">
    <view v-for="item in list" :key="item" @click="jump(item.push)">{{item.name}}</view>
  </view>
  <!-- 补液单价 -->
  <Price @submit="submit" ref="AddPrice" type="Rehydrator"></Price>
</template>

<script setup lang="ts">
  import { navBack, navTo } from '@/utils/navigator';
  import { errorToast, showLoading, successToast } from '@/utils/prompt';
  import { toPublish } from '@mqtt';
  import Price from '@c/administrator/BulletBox/price.vue';
  import { onLoad, onUnload } from '@dcloudio/uni-app';
  import { ref } from 'vue';
  import { information } from '@/stores/administrator';
  const TeamInfo = information();
  const AddPrice = ref(null)
  const list = [
    { name: '账户明细', push: 'administrator/rehydrator/accountDetails' },
    { name: '补液单价' },
    { name: '补液记录', push: 'administrator/rehydrator/fluidList' },
    { name: '售液记录', push: 'administrator/rehydrator/sellFill' },
    { name: '加注机', push: 'administrator/rehydrator/fillList' },
    { name: '补液员列表', push: 'administrator/rehydrator/rehydrator' },
    { name: '移库单', push: 'administrator/rehydrator/relocationList' },
    { name: '采购入库', push: 'administrator/rehydrator/outboundList' }]
  const stationID = ref('')
  onLoad((pearm) => {
    stationID.value = pearm.id
    TeamInfo.rehydration(stationID.value)
  })
  // 填写司机价
  function submit(num : number) {
    console.log(num)
    showLoading('正在提交');
    const payload = {
      delivery_id: Number(stationID.value),
      price: num
    };
    toPublish('control/editDeliveryPrice', payload, (obj : any) => {
      const { code, msg } = obj;
      if (code === 1) {
        successToast('提交成功');
        TeamInfo.rehydration(stationID.value)
      } else {
        errorToast(msg);
      }
    });
  }
  function jump(push : string) {
    if (push) {
      navTo(push)
    } else {
      AddPrice.value.openBankPad()
    }
  }
  onUnload(() => {
    uni.removeStorageSync('station');
  })
</script>

<style scoped lang="less">
  .ability {
    flex-wrap: wrap;

    view {
      width: 48.5%;
      height: 102rpx;
      background: #FFFFFF;
      border: 1px solid #EEF3F7;
      border-radius: 6px;
      text-align: center;
      line-height: 102rpx;
      margin-bottom: 15rpx;
    }
  }
</style>